package com.zpyr.common;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class SessionManager {
	
	private static final String SESSION_STR_LOGIN_EMAIL = "ZPYR_LOGIN_EMAIL_SESS";
	private static final String SESSION_STR_LOGIN_TIME = "ZPYR_LOGIN_TIME_SESS";
	
	private static final SessionManager sessionManager = new SessionManager();
	private static HttpSession currentSession = null;
	
	private SessionManager() {
		
	}
	
	public static SessionManager getInstance(HttpServletRequest req) {
	
		
		currentSession = req.getSession(true);
		
		return sessionManager;
	}
	
	public void setLoginEmail(String login_email) {
		currentSession.setAttribute(SESSION_STR_LOGIN_EMAIL , login_email);
	}
	
	public void setLoginTime(String login_time) {
		currentSession.setAttribute(SESSION_STR_LOGIN_TIME , login_time);
	}

	public String getLoginEmail() {
		return currentSession.getAttribute(SESSION_STR_LOGIN_EMAIL) == null? "" : (String) currentSession.getAttribute(SESSION_STR_LOGIN_EMAIL);
	}
	
	public String getLoginTime() {
		return currentSession.getAttribute(SESSION_STR_LOGIN_TIME) == null? "" : (String) currentSession.getAttribute(SESSION_STR_LOGIN_TIME);
	}
	
	public void removeLoginEmail() {
		currentSession.removeAttribute( SESSION_STR_LOGIN_EMAIL );
	}

	public void removeLoginTime() {
		currentSession.removeAttribute( SESSION_STR_LOGIN_TIME );
	}
	
	public void logout() {
		currentSession.invalidate();
	}

}
